package leetcode.L1000;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class EX690 {
    class Employee {
        public int id;
        public int importance;
        public List<Integer> subordinates;
    };
//把所有员工的id和员工的索引通过哈希表关联上，递归遍历员工

    int res = 0;
    Map<Integer,Integer> map ;
    public int getImportance(List<Employee> employees, int id) {
        map = new HashMap<Integer,Integer>();
        for(int i = 0;i<employees.size();i++){
            map.put(employees.get(i).id,i);
        }
        dsp(employees,id);
        return res;
    }
    public void dsp(List<Employee> employees, int id){
        Employee employee= employees.get(map.get(id));
        res+=employee.importance;
        for(int each : employee.subordinates){
            dsp(employees,each);
        }
    }

}
